﻿Imports System.IO
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim sourceText = RichTextBox1.Text
        Dim distPath = TextBox1.Text
        'instance是 fileunits类的一个实例
        Dim instance = New fileunits
        instance.writeToFile(sourceText, distPath)
    End Sub
    Private Sub Form1_load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        RichTextBox1.Text = ""
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        RichTextBox2.Text = ""
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim instance = New fileunits
        Dim sourePath = Application.StartupPath & "\999.txt"
        Dim sourceContent = instance.readFromFile(sourePath)
        RichTextBox2.Text = sourceContent
    End Sub
    Private Sub Button5_Click_1(sender As Object, e As EventArgs) Handles Button5.Click
        SaveFileDialog1.Filter = "(*.txt)|*.txt"
        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            TextBox1.Text = SaveFileDialog1.FileName
        End If
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        MsgBox(DateTime.Now.Ticks)
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            TextBox2.Text = OpenFileDialog1.FileName
        End If
    End Sub

End Class


'fileunits是一个用户自定义的工具类
Public Class fileunits
        '定义一个写文件操作的sub函数
        Public Sub writeToFile(content As String, path As String)
            Dim swriter = New StreamWriter(path)
            swriter.WriteLine(content)
            swriter.Close()
        End Sub
        Public Function readFromFile(path As String) As String
            Dim sreader = New StreamReader(path)
            Dim content = sreader.ReadLine()
            Return content
        End Function
    End Class


